<?php


namespace api\controllers;


use api\components\BaseController;
use common\helpers\commonApi;
use common\helpers\WeChatApi;
use common\models\Dis;
use common\models\Order;
use common\models\System;
use common\models\User;
use Yii;

/**
 * 分销用户
 * Class DisController
 * @package api\controllers
 */
class DisController extends BaseController
{
    /**
     * 分销用户列表
     * @return array
     */
    public function actionUser()
    {
        $get = Yii::$app->request->get();
        $userid = $get['userid']??self::$userid;
        $page = $get['page']??1;
        $model = new User();
        return $model->disUser($userid,$page);
    }

    /**
     * 分销订单
     * @return array
     */
    public function actionOrder()
    {
        $get = Yii::$app->request->get();
        $userid = $get['userid']??'';
        $page = $get['page']??1;
        $status = $get['status']??'';
        $model = new Order();
        return $model->disOrder(self::$userid,$userid,$status,$page);
    }

    /**
     * 分销数据
     * @return array
     */
    public function actionStatistics()
    {
        $userid = self::$userid;
        $model = new User();
        return $model->disStatistics($userid);
    }

    /**
     * 获取海报
     * @return array
     */
    public function actionPoster()
    {
        return (new User())->poster(self::$userid);
    }

    /**
     * 申请
     * @return array
     */
    public function actionApply()
    {
        $post = Yii::$app->request->post();
        $model = new Dis();
        return $model->apply(self::$userid,$post);
    }

    /**
     * 开关
     * @return array
     */
    public function actionSwitch()
    {
        $post = Yii::$app->request->post();
        $userid = $post['userid']??'';
        if (!$userid){
            return commonApi::message('请选择用户',false);
        }
        $model = new Dis();
        return $model->switchs(self::$userid,$userid);
    }
}